home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day11 / dbgmain.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  4.1 KB  |  122 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #include <checks.h>
  4. #pragma hdrstop
  5. #include "DbgMain.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8. TMainForm *MainForm;
  9. //---------------------------------------------------------------------------
  10. __fastcall TMainForm::TMainForm(TComponent* Owner)
  11.   : TForm(Owner)
  12. {
  13.   OutputDebugString("Log file created.");
  14.   OutputDebugString("Constructor executed.");
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TMainForm::WatchBtnClick(TObject *Sender)
  18. {
  19.   OutputDebugString("WatchBtnClick() executed.");
  20.   //
  21.   // Add watches to the Watch List for the s, x, and y
  22.   // variables. Watch the variables change as you step
  23.   // through the code.
  24.   //
  25.   String s;
  26.   int x = Width;
  27.   s = String(x);
  28.   int y = Height;
  29.   x *= y;
  30.   s = String(x);
  31.   x /= y;
  32.   // SET A BREAKPOINT ON THE FOLLOWING LINE
  33.   s = "s = " + String(x);
  34.   OutputDebugString(s.c_str());
  35.   //
  36.   // The following function beeps the speaker. You
  37.   // can either Step Over the function (F8) or you
  38.   // can OutputDebugString Into the function (F7). Try it both
  39.   // ways to see the difference
  40.   //
  41.   BeepFunction();
  42.   //
  43.   // Click the Run button again now to return to
  44.   // the Debug Test program.
  45.   //
  46.   Width = x;
  47.   Height = y;
  48. }
  49. //---------------------------------------------------------------------
  50. void __fastcall TMainForm::CrashBtnClick(TObject *Sender)
  51. {
  52.   OutputDebugString("CrashBtnClick() executed.");
  53.   //
  54.   // The second line below should be highligted
  55.   // showing you that the program failed on that
  56.   // line. The reason the program failed there is
  57.   // because the 'list' pointer was never intialzied.
  58.   // This is a controlled crash because since we have
  59.   // set the 'list' variable to 0 we know that it
  60.   // does not contain some random data. You will have
  61.   // to choose Run | Program Reset from the main menu
  62.   // to terminate the program.
  63.   //
  64.   TStringList* list = 0;
  65.   list->Add("test");
  66. }
  67. //---------------------------------------------------------------------
  68. void __fastcall TMainForm::BadCrashBtnClick(TObject *Sender)
  69. {
  70.   OutputDebugString("BadCrashBtnClick() executed.");
  71.   //
  72.   // You will probably never get here while debugging.
  73.   // The program crashes because the 'list' pointer
  74.   // is never initialized and contains some random data.
  75.   // When we attempt to call a function the program
  76.   // jumps off to who-knows-where and tromps on some
  77.   // memory somewhere.
  78.   //
  79.   TStringList* list;
  80.   list->Add("test");
  81. }
  82. //---------------------------------------------------------------------
  83. void TMainForm::BeepFunction()
  84. {
  85.   OutputDebugString("BeepFunction() executed.");
  86.   //
  87.   // If you are here it is because you have used
  88.   // OutputDebugString Into (F7} from the WatchButtonClick()
  89.   // function.
  90.   //
  91.   MessageBeep(-1);
  92. }
  93. void __fastcall TMainForm::InspectBtnClick(TObject *Sender)
  94. {
  95.   OutputDebugString("InspectBtnClick() executed.");
  96.   TStringList* list = new TStringList();
  97.   list->Add("This is a test");
  98.   list->Add("Josh, Jenna, James");
  99.   // SET A BREAKPOINT ON THE FOLLOWING LINE
  100.   list->Add("Marshall, Mallory, Mason");
  101.   //
  102.   // Inspect an object. Click on the word 'list' above
  103.   // and choose Inspect from the speed menu or press
  104.   // Alt-F5. The Debug Inspector will be displayed.
  105.   //
  106.   // After you are done inspecting the 'list' object
  107.   // choose Run | Inspect from the main menu. When the
  108.   // Inspect dialog box comes up type 'this' in the
  109.   // Expression field and click OK. You will then be
  110.   // able to inspect the main form class.
  111.   //
  112.   delete list;
  113.   // Click the Run button again to return control
  114.   // back to the Debug Test program.
  115. }
  116. //---------------------------------------------------------------------
  117. void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
  118. {
  119.   OutputDebugString("FormClose() executed.");
  120. }
  121. //---------------------------------------------------------------------------
  122.